# -*- coding: UTF-8 -*-
import json

from flask import make_response, jsonify

from api.utils.CustomJSONEncoder import CustomJsonEncoder
from core.dto.ResponseDtos import PoleGuyDataRespnseDTO
from core.dto.base import BaseDTO


class Response(object):
    @staticmethod
    def default(obj):
        if isinstance(obj, PoleGuyDataRespnseDTO):
            return obj.__dict__
        raise TypeError(f'Object of type {obj.__class__.__name__} is not JSON serializable')

    @staticmethod
    def make_response(dto, status=200):
        if isinstance(dto, PoleGuyDataRespnseDTO):
            #return make_response(jsonify(dto), status)
            return make_response(json.dumps(dto, default=Response.default))
        elif isinstance(dto, BaseDTO):
            return make_response(jsonify(dto), status)
            #return make_response(json.dumps(dto, cls=CustomJsonEncoder))
        else:
            pass
